@extends('Admin.Index.index')
@section('title')
    修改商品分类
@endsection
@section('content')
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-admin-role-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">* </span>新的分类名称：</label>
            <div class="formControls col-xs-5 col-sm-6">
                <input type="text" placeholder="分类名称" value="{{$info->c_name}}" class="input-text" id="className">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">* </span>标签：</label>
            <div class="formControls col-xs-5 col-sm-6">
                <span class="select-box" >
                <select class="select" name="brandclass" size="1" id="tag_id">
                    @foreach($tag_list as $vv)
                        <option value="{{$vv->tag_id}}" selected>{{$vv->tag_name}}</option>
                    @endforeach
                </select>
			</span>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="button" class="btn btn-success radius" id="edit_class" name="admin-role-save">
                    <i class="icon-ok"></i> 确定
                </button>
            </div>
        </div>
    </form>
</article>
<script type="text/javascript">
    $(function(){
        var c_id = "{{$info->c_id}}";

        /**
         * 分类名称的初步验证
         */
        $('#className').blur(function () {
            var name = $('#className').val();
            if(name.length == 0)
            {
                layer.msg('分类名称不能为空',{icon:5});
            }else if(name.length >10 || name.length  <2)
            {
                layer.msg('请输入2~10位分类名称',{icon:5});
            }
            var p = /^[*&^%$#@!?]+$/;
            if (p.exec(name))
            {
                layer.msg('分类名称不能带符号',{icon:5});
            }
        });

        $('#edit_class').click(function () {
            var name = $('#className').val();

            if(name.length == 0)
            {
                layer.msg('分类名称不能为空',{icon:5});
                return false;
            }

            var tag_id = $('#tag_id').val();
            layer.load(2);
            $.post('',{name:name,c_id:c_id,tag_id:tag_id},function (e) {
                console.log(e);
                layer.closeAll('loading');
                if(e.status)
                {
                    window.parent.location.reload();
                }else{
                    layer.msg(e.info,{icon:5});
                }
            })


        });

    });
</script>
@endsection